﻿using GraphProcessor;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.Teleport, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_Teleport : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.Teleport;

        public override string name => LevelEditorConst.Teleport;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "RegionInstance表ID(目的地地区选择)")]
        public int regionCid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "落点:实体ID(0为自己,-1为null(原点))")]
        public int portalTagOrMcid;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "相对坐标(相对落点实体的偏移)")]
        public Vector3 pos;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "传送结束改变朝向")]
        public bool isSetRotation;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.Teleport, "传送结束的朝向rotationY")]
        public int rotationY;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            return new LevelServiceExecutionCustom_Teleport()
            {
                regionCid = this.regionCid,
                portalTagOrMcid = this.portalTagOrMcid,
                isSetRotation = this.isSetRotation,
                rotationY = this.rotationY,
                position = new Int3(this.pos * 100)
            };
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_Teleport rNode)
            {
                this.regionCid = rNode.regionCid;
                this.portalTagOrMcid = rNode.portalTagOrMcid;
                this.isSetRotation = rNode.isSetRotation;
                this.pos = rNode.pos;
                this.rotationY = rNode.rotationY;
            }
        }
    }
}